package io.nads.context;

public class BaseContext {

    public static class ContextData {
        private Long id;
        private Long sessionId;

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public Long getSessionId() {
            return sessionId;
        }

        public void setSessionId(Long sessionId) {
            this.sessionId = sessionId;
        }
    }

    public static ThreadLocal<ContextData> contextThreadLocal = new ThreadLocal<ContextData>() {
        @Override
        protected ContextData initialValue() {
            return new ContextData();
        }
    };

    public static void setCurrentId(Long id) {
        contextThreadLocal.get().setId(id);
    }

    public static Long getCurrentId() {
        return contextThreadLocal.get().getId();
    }

    public static void setCurrentSessionId(Long sessionId) {
        contextThreadLocal.get().setSessionId(sessionId);
    }

    public static Long getCurrentSessionId() {
        return contextThreadLocal.get().getSessionId();
    }

    public static void removeAll() {
        contextThreadLocal.remove();
    }
}